[PW_SID:1056145] [v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1487
[PW_SID:1056145] [v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1487linux-riscv-bot wants to merge 1 commit intoworkflow__riscv__fixesfrom
Conversation
Currently, kvm_arch_vcpu_load() unconditionally restores guest CSRs and HGATP. However, when a preempted VCPU is scheduled back on the same physical CPU, and no other KVM VCPU has run on this CPU in the meantime, the hardware CSRs are still valid. This patch optimizes the vcpu_load path by skipping the expensive CSR writes if all the following conditions are met: 1. The VCPU was previously preempted (vcpu->scheduled_out == 1). 2. It is being reloaded on the same CPU (vcpu->arch.last_exit_cpu == cpu). 3. No other VCPU used this CPU (vcpu == __this_cpu_read(kvm_former_vcpu)). 4. The CSRs are not dirty (!vcpu->arch.csr_dirty). To ensure this fast-path doesn't break corner cases: - Live migration and VCPU reset are naturally safe. KVM initializes last_exit_cpu to -1, which guarantees the fast-path won't trigger. - A new 'csr_dirty' flag is introduced to track runtime userspace interventions. If userspace modifies guest configurations (e.g., hedeleg via KVM_SET_GUEST_DEBUG, or CSRs via KVM_SET_ONE_REG) while the VCPU is preempted, the flag is set to skip fast path. Note that kvm_riscv_vcpu_aia_load() is kept outside the skip logic to ensure IMSIC/AIA interrupt states are always properly synchronized. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
|
Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core" |
PR for series 1056145 applied to workflow__riscv__fixes
Name: [v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1056145
Version: 4